#include "PlayerInfo.h"
#include "cocos2d.h"
#define kPlayerNewGame "player_newgame"
#define kPlayedTutorialEasy "played_tutorial_easy"
#define kPlayedTutorialNormal "played_tutorial_normal"
#define kPlayedTutorialHard "played_totorial_hard"
USING_NS_CC;

PlayerInfo* PlayerInfo::m_instance = nullptr;

PlayerInfo* PlayerInfo::getInstance()
{
	if (m_instance == nullptr)
		m_instance = new PlayerInfo();
	return m_instance;
}

PlayerInfo::PlayerInfo()
{
	level = new LevelInfo();
	iap = new IAPInfo();

	if (!UserDefault::getInstance()->getBoolForKey(kPlayerNewGame))
	{
		reset();
	}
}

void PlayerInfo::reset()
{
	UserDefault::getInstance()->setBoolForKey(kPlayerNewGame, true);
	level->reset();
	iap->reset();
	UserDefault::getInstance()->setBoolForKey(kPlayedTutorialEasy, false);
	UserDefault::getInstance()->setBoolForKey(kPlayedTutorialNormal, false);
	UserDefault::getInstance()->setBoolForKey(kPlayedTutorialHard, false);
}	
void PlayerInfo::setPlayedTutorial(EGameMode gameMode)
{
    switch (gameMode) {
        case kMode_Easy:
            UserDefault::getInstance()->setBoolForKey(kPlayedTutorialEasy,true);
            break;
        case kMode_Normal:
            UserDefault::getInstance()->setBoolForKey(kPlayedTutorialNormal,true);
            break;
        case kMode_Hard:
            UserDefault::getInstance()->setBoolForKey(kPlayedTutorialHard,true);
            break;
        default:
            return;
    }
}
bool PlayerInfo::getPlayedTutorial(EGameMode gameMode)
{
    switch (gameMode) {
        case kMode_Easy:
            return UserDefault::getInstance()->getBoolForKey(kPlayedTutorialEasy,false);
            
        case kMode_Normal:
            return UserDefault::getInstance()->getBoolForKey(kPlayedTutorialNormal,false);
        case kMode_Hard:
            return UserDefault::getInstance()->getBoolForKey(kPlayedTutorialHard,false);
        default:
            return false;
    }
}